﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using Core.Base;
using System.Data;
using ERP.BusinessEntities;
using System.Windows.Forms;
using System.Transactions;

namespace MainApp.Modules.NumberConfig
{
    public class NumberConfigModule: BaseModule
    {
        public NumberConfigModule()
        {
            this.Name = "NumberConfig";
            entity = new NumberConfigEntity();
            Init();
        }


        public override void LoadData()
        {
            base.LoadData();

            DataSet dsNumberConfigs = AppContext.NumberCfgCtrl.GetAllObjects();
            ((NumberConfigEntity)entity).lstNumberConfigs.Invalidate(dsNumberConfigs);
            ((NumberConfigEntity)entity).lstNumberConfigs.GridView.AllowUserToAddRows = true;
        }

        public override void ActionSave()
        {
            using (TransactionScope tranScope = new TransactionScope(TransactionScopeOption.RequiresNew, new TimeSpan(1, 10, 30)))
            {
                try
                {
                    AppContext.NumberCfgCtrl.GetDataset(@"DELETE BSNumberConfigs");
                    foreach (BSNumberConfigsInfo NumberConfig in ((NumberConfigEntity)entity).lstNumberConfigs)
                    {
                        AppContext.NumberCfgCtrl.CreateObject(NumberConfig);
                    }

                    tranScope.Complete();
                    MessageBox.Show("Save successfuly");
                }
                catch (Exception)
                {
                    tranScope.Dispose();
                }
            }

        }
       
    }
}
